#include <stdio.h> int main() { int i = 5; char c = 'c'; float pi = 3.14; return (1); }
int i; i = 5;
Type | Translation | Examples |
---|---|---|
int | integer | -427, 5000 |
short | short integer | -27, 241 |
long | long integer | -125000, 251425 |
unsigned | unsigned integer | 26, 15842 |
char | character | 'a', 'q' |
unsigned char | unsigned character | 12, 255 |
float | floating point number | 3.14, 7.95 |
double | double precision number | 3.1415926, 6.245187 |
bool | boolean value | true, false |
Operator | Translation | Uses |
---|---|---|
= | Assignment Operator | Assign a value to a variable |
+ | Addition Operator | Adds two values together |
- | Subtraction Operator | Subtracts 1 number from another |
* | Multiplication Operator | Multiplies two values together |
/ | Division Operator | Divides 1 number by another |
== | Conditional Equality Operator | Test if variables are equal |
> | Greater Than Operator | Test if 1 variable is more than another |
< | Less Than Operator | Test if 1 variable is less than another |
&& | Logical And Operator | Used to combine two or more statements together |
|| | Logical Or Operator | Same as Logical And Operator |
& | Bitwise And Operator | Used to combine two variables together |
| | Bitwise Or Operator | Same as above |
^ | Bitwise Xor Operator | Same as above |
<< | Left Shift Operator | Shift the bits of a variable to the left |
>> | Right Shift Operator | Shift the bits of a variable to the right |
~ | Ones Complement Operator | Switch all bits from 0 to 1 and 1 to 0 |
& | Reference Operator | Used in function calls to denote the address of a variable |
<variable> = <value or other variable>;
float f = 7.11; int i = 5; char c = 'g';
int i; scanf("%i", &i);
Type | Printf/Scanf Code |
---|---|
integer | %i |
short int | %hi |
long int | %li |
unsigned int | %u |
char | %c |
string | %s |
float | %f |
double | %f |
#include <stdio.h> int main() { /* Print to Screen */ printf ("Hey World, how's it going?\n"); return (1); }
#include <stdio.h> void Print() { /* Print to Screen */ printf ("Hey World, how's it going?\n"); return; } int main() { Print(); return (1); }
void Print()
<return type> <function name> (<argument 1 type> <argument 1 name>, ... )
#include <stdio.h> int Print( int i ) { i = i + 5; /* Print to Screen */ printf ("The value of the argument has changed\n"); return (i); } int main() { int number; /* Get a number from the user */ scanf ("%i", &number); Print(number); return (1); }